package simco.framework.gui.swing.comp;

import java.awt.BorderLayout;
import java.util.ResourceBundle;

import javax.swing.DefaultListSelectionModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import simco.framework.gui.services.data.CalendarModel;
import simco.framework.gui.utils.LocalizationUtil;

/**
 * Tato trida reprezentuje panel, na nejz je vykreslovan kalendar
 * udalosti.
 * 
 * @author Matej Prokop, mythge@students.zcu.cz
 *
 */
public class CalendarPanel extends JPanel
{	
	/**
	 * Tlacitko prejdi na udalost
	 */
	private JButton goToEventBtn;
	
	/**
	 * Reference na bundle obsahujici lokalizaci
	 */
	private ResourceBundle locResource;
	
	/**
	 * Vytvori novy panel s kalendarem udalosti
	 * @param calendarModel datovy model kalendare udalosti
	 */
	public CalendarPanel( CalendarModel calendarModel )
	{		
		this.setLayout(new BorderLayout());		
		
		locResource = LocalizationUtil.getResource(GuiMainFrame.class.getSimpleName());
		
		initComponents(calendarModel);
	}

	/**
	 * Vraci tlacitko pro prejiti na vybranou udalost
	 * @return tlacitko pro prejiti na vybranou udalost
	 */
	public JButton getGoToEventBtn() 
	{
		return goToEventBtn;
	}
	
	/**
	 * Rozmisti komponenty po panelu
	 * @param calendarModel datovy model kalendare udalosti
	 */
	private void initComponents(CalendarModel calendarModel)
	{		
		JLabel label = new JLabel(locResource.getString("calendar.contentTitle") + ":");
		this.add( label, BorderLayout.PAGE_START );
				
		goToEventBtn = new JButton(locResource.getString("calender.jumpToEvent"));
		this.add( goToEventBtn, BorderLayout.PAGE_END );
		
		JList calContent = new JList( calendarModel );
		calContent.addListSelectionListener( calendarModel );
		calContent.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
		calContent.setCellRenderer( calendarModel.getCellRenderer() );		
		calendarModel.setCalendarList(calContent);
		
		JScrollPane scroll = new JScrollPane(calContent);
		this.add( scroll, BorderLayout.CENTER );		
	}
}
